# Contributor: Runar Tenfjord < runar dot tenfjord at gmail dot com >
# Contributor: Ray Donnelly <mingw.android@gmail.com>

_pyname=Cython
_realname=cython
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-cython")
pkgver=0.29.35
pkgrel=2
pkgdesc="C-Extensions for Python (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32' 'clangarm64')
url="https://cython.org/"
license=('spdx:Apache-2.0')
depends=("${MINGW_PACKAGE_PREFIX}-python")
makedepends=("${MINGW_PACKAGE_PREFIX}-python-build"
             "${MINGW_PACKAGE_PREFIX}-python-installer"
             "${MINGW_PACKAGE_PREFIX}-python-setuptools"
             "${MINGW_PACKAGE_PREFIX}-python-wheel"
             "${MINGW_PACKAGE_PREFIX}-cc")
options=(!strip)
source=("https://pypi.org/packages/source/${_pyname::1}/${_pyname}/${_pyname}-${pkgver}.tar.gz")
sha256sums=('6e381fa0bf08b3c26ec2f616b19ae852c06f5750f4290118bf986b6f85c8c527')

prepare() {
  rm -rf python-build-${MSYSTEM}| true
  cp -r "${_pyname}-${pkgver}" "python-build-${MSYSTEM}"
}

build() {
  cd "${srcdir}/python-build-${MSYSTEM}"
  ${MINGW_PREFIX}/bin/python -m build --wheel --skip-dependency-check --no-isolation
}

package() {
  cd "${srcdir}/python-build-${MSYSTEM}"
  MSYS2_ARG_CONV_EXCL="--prefix=" \
    ${MINGW_PREFIX}/bin/python -m installer --prefix=${MINGW_PREFIX} \
    --destdir="${pkgdir}" dist/*.whl

  # Remove a warning about srcdir
  _src="$(cygpath -m $srcdir)"
  find ${pkgdir}/ -name "*.txt" -exec sed -e "s|$_src\/||g" -e "s|python-build-${MSYSTEM}\/||g" -i {} \;
}
